package com.persondemo.videoappliction.ui.duanzi.presenter;

import com.persondemo.videoappliction.bean.DetilsBean;
import com.persondemo.videoappliction.bean.HFBean;
import com.persondemo.videoappliction.bean.PingLunBean;
import com.persondemo.videoappliction.bean.ZanCaiBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.duanzi.contract.DetilsContract;

import javax.inject.Inject;

/**
 * Created by Administrator on 2018/4/23.
 */

public class DetilsPresenter extends BasePresenter<DetilsContract.View> implements DetilsContract.Presenter {
    BaseApi baseApi;

    @Inject
    public DetilsPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void getdata(String ids) {
        baseApi.getdetils(ids)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<DetilsBean>() {
                    @Override
                    public void onSuccess(DetilsBean detilsBean) {
                        mView.loaddata(detilsBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void getpinlun(String ids, String page) {
        baseApi.getpinlundata(ids, page)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<PingLunBean>() {
                    @Override
                    public void onSuccess(PingLunBean pingLunBean) {
                        if (Integer.parseInt(page) > 1) {
                            mView.pinlunmore(pingLunBean);
                        } else {
                            mView.loadpinlundata(pingLunBean);
                        }
                    }
                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
    @Override
    public void zancaiping(String ids, String type, String device) {
        baseApi.getinfor(ids, type, device)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<ZanCaiBean>() {
                    @Override
                    public void onSuccess(ZanCaiBean zanCaiBean) {
                        mView.getzcp(zanCaiBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void getHf(String ids, String content, String device, String mid) {
        baseApi.getHf(ids, content, device, mid)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<HFBean>() {
                    @Override
                    public void onSuccess(HFBean hfBean) {
                        mView.getHF(hfBean);
                    }
                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
}
